package com.zxy.rabbitmqdemo.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

/**
 * RabbitMQDemoListener.
 * 
 * Created by zxybird on 16/10/31.
 */
public class RabbitMQDemoListener implements MessageListener {

  protected final Logger LOG = LoggerFactory.getLogger(getClass());

  public void onMessage(Message message) {
    String msg = null;
    try {
      msg = new String(message.getBody(), "UTF-8");
      LOG.info("received a new message: {}.", msg);
//      Map<String, Object> msgMap = jsonParser.toMap(msg);
//      if (CollectionUtils.isEmpty(msgMap)) {
//        throw new IllegalArgumentException("empty message!");
//      } else {
//        handleMessage(msgMap);
//      }
    } catch (Exception e) {
      LOG.error("handle message: {} failed.", msg, e);
    }
  }
}
